<template>
    <view class="content">
        <view class="class1">
            <view class="item" v-for="(item, index) in list" :key="index" @click="$gTo('/pages/activity/details?id=' + item.id)">
                <image :src="item.image" class="act-img"></image>
                <view class="item-right">
                    <view class="time">{{item.enroll_start}}-{{item.enroll_end}}</view>
                    <view class="name">{{item.title}}</view>
                    <view class="start">活动开始：{{item.start_time}}</view>
                    <!-- is_enroll 报名人数: 1显示 2隐藏 -->
                    <view class="nums" v-if="is_enroll == 1">
                        <image src="../../static/icon/us.png" class="us"></image>
                        报名人数：<text class="num">{{item.num}}</text>/{{item.enroll_num}}
                    </view>
                    <!-- status 1活动进行中（报名未结束）、2进行中（报名已结束）、 3活动已结束 -->
                    <view class="item-down">
                        <view class="btn" v-if="item.status == 1">立即报名</view>
                        <view class="btn btn2" v-if="item.status == 2">报名结束</view>
                    </view>
                </view>
            </view>
            
            <view style="height: 94rpx;padding-top: 30rpx;">
                <u-loadmore :status="status" v-if="status != 'loadmore'" />
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
                is_enroll: 0,
            };
        },
        onShow() {
            this.page = 1
            this.list = []
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            // 获取列表
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('activity_list', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    status: 1,//1进行中活动 2往期活动
                    type: '',//类型
            	}).then(ret => {
            		if (ret.success == 1000) {
                        this.is_enroll = ret.detail.is_enroll
            			if (ret.detail && ret.detail.activity && ret.detail.activity.length > 0) {
            				this.list = this.list.concat(ret.detail.activity);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    page{
        background-color: #f5f5f5;
    }
    .class1 {
    	height: 400rpx;
    	width: 100%;
    	background: linear-gradient(180deg, #3dc2ef, #71deed, #f5f5f5);
        padding: 30rpx 25rpx;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        background-color: #fff;
        border-radius: 20rpx;
        padding: 30rpx;
        margin-bottom: 20rpx;
    }
    .act-img{
        width: 220rpx;
        height: 320rpx;
        border-radius: 10rpx;
        margin-right: 20rpx;
    }
    .item-right{
        flex: 1;
    }
    .time{
        font-size: 24rpx;
        color: #a5a5a5;
        padding-bottom: 10rpx;
    }
    .name{
        font-size: 28rpx;
        font-weight: bold;
        line-height: 32rpx;
        height: 64rpx;
        display: -webkit-box;
        overflow: hidden;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }
    .start{
        font-size: 24rpx;
        padding: 10rpx 0;
    }
    .nums{
        display: flex;
        justify-content: flex-start;
        align-items: center;
        font-size: 22rpx;
        padding: 7rpx 15rpx;
        background-color: #f5f5f5;
    }
    .us{
        width: 23rpx;
        height: 19rpx;
        margin-right: 7rpx;
    }
    .num{
        font-size: 28rpx;
        color: #f62a2a;
    }
    .item-down{
        display: flex;
        justify-content: flex-end;
        align-items: center;
        padding-top: 50rpx;
    }
    .btn{
        width: 158rpx;
        height: 56rpx;
        font-size: 26rpx;
        color: #7d664b;
        line-height: 56rpx;
        text-align: center;
        background: linear-gradient(to top, #ffdbad, #fff4e4);
        border-radius: 15rpx;
    }
    .btn2{
        color: #fff;
        background: #808080;
    }

</style>
